import { _decorator, Collider2D, Component, Contact2DType, IPhysics2DContact, Node, tween, Vec3, find, UITransform } from 'cc';
import { ExpWnd } from './ExpWnd';
const { ccclass, property } = _decorator;

@ccclass('SunExp')
export class SunExp extends Component {

    start() {
        const player = find("Canvas/Player");
        if (!player) return;

        const targetPos = player.getComponent(UITransform).convertToWorldSpaceAR(new Vec3(0, 0, 0));
        const localPos = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(targetPos);

        // 使用tween创建动画
        tween(this.node)
            .to(1, { position: localPos }, { easing: 'sineOut' })
            .call(() => {
                // 动画结束后销毁节点
                ExpWnd.getInstance().addExp(10);
                this.scheduleOnce(() => {
                    this.node.destroy();
                }, 0.1);
            })
            .start();
    }
}
